import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'tenantM',
  state: {},
  effects: {
    // 租户列表
    *getTenantList({ payload, callback }, { call, put }) {
      const response = yield call(api.userManageNew.SearchTenant, payload);
      if (response && response.code == 0) {
        let tempArr = [];
        response.data.dataSource &&
          response.data.dataSource.forEach((item) => {
            tempArr.push({ value: item.code, title: item.name, id: item.id, reportScenario: item.reportScenario, reportTemplate: item.reportTemplate });
          });
        callback(tempArr);
      } else {
        message.error(response && response.msg ? response.msg : '查询失败!');
      }
    },
    // 部门列表
    *getDepartmentList({ payload, callback }, { call, put }) {
      const response = yield call(api.getDepartmentList, payload);
      if (response && response.code == 0) {
        let tempArr = [];
        response.data.dataSource &&
          response.data.dataSource.forEach((item) => {
            tempArr.push({ value: item.orgName, title: item.orgName, id: item.id });
          });
        callback(tempArr);
      } else {
        message.error(response && response.msg ? response.msg : '查询失败!');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
